package com.example.boot.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;

import com.example.boot.rtorder.model.RtOrder;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;

import net.sf.json.JSONObject;


public class JSONToObj {
	public Object JsonToClass(String json,Object o) throws JsonParseException, JsonMappingException, IOException {
		JSONObject jsonObj=JSONObject.fromObject(json);
		Object o1 = JSONObject.toBean(jsonObj,o.getClass());
		return o1;

	}
	public static void main(String[] args) throws JSONException, JsonParseException, JsonMappingException, IOException {
		String json = "{'id': '402881e85fe28395015fe2863e130007','goodsList':[{'bpmStatus':1,'id':'dsadas'},{'bpmStatus':'2'}]}";
		org.json.JSONObject jd = new org.json.JSONObject(json);
		JSONToObj j = new JSONToObj();
		JSONObject jss= JSONObject.fromObject(json);
		net.sf.json.JSONArray jdd = jss.getJSONArray("goodsList");
		for(int i =0;i<jdd.size();i++){ 
			String rto = jdd.get(i).toString();
			RtOrder jsonToClass = (RtOrder) j.JsonToClass( rto,new RtOrder());
			System.out.println("+++");
			
		}
		
		System.out.println(jdd.toString());
//		System.out.println(jss.toString());
//		JSONArray jsonArray = jd.getJSONArray("goodsList");
//		List<RtOrder> list = new ArrayList<>();
//		for(int i =0;i<jsonArray.length();i++){
//			
//		}
		
//		try {
//			RtOrder jsonToClass = (RtOrder) j.JsonToClass( json,new RtOrder());
//			System.out.println(jsonToClass.toString());
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
}
